package com.example.trans.controller;

import com.example.trans.service.LogInfoService;
import com.example.trans.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/prop")
public class PropagationController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private LogInfoService logInfoService;

    @Transactional(propagation = Propagation.REQUIRED)
    @RequestMapping("/insert")
    public boolean insert(String userName, String password){
        // 用户注册
        userInfoService.insertUserInfo(userName, password);
        // 用户操作
        logInfoService.insertLogInfo(userName, "用户注册");

        return true;
    }
}
